package com.situ.crm.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.ParameterType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig{

    // http://localhost:8081/swagger-ui/index.html
    // http://localhost:8080/doc.html

    // 配置swagger2核心配置 docket
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2) //指定api类型为swagger2
                .groupName("RbacApi") //指定分组
                .apiInfo(getApiInfo()) //用于定义api文档汇总信息
                .select()
                .paths(PathSelectors.regex("/rbac/.*"))
                .build()
                .globalRequestParameters(
                    Collections.singletonList(new RequestParameterBuilder()
                            .name("token")
                            .description("用户token")
                            .in(ParameterType.HEADER)
                            .required(false)
                            .build()));
    }

    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("思途CRM后台接口api")// 文档页标题
                .contact(new Contact("situ", "https://www.situ.com", "abc@situ.com"))// 联系人信息
                .description("思途CRM后台接口提供的api文档") //详细信息
                .version("1.0.1")  //文档版本号
                .termsOfServiceUrl("https://www.situ.com") //网站地址
                .build();
    }

}
